{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e70cebe9-050c-4e20-a4bd-caa1605fe852",
   "metadata": {},
   "source": [
    "Chapter 04\n",
    "# 条件语句\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c7cbb54f-3add-4b61-adeb-3a0e14a186ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x is positive\n",
      "该数值的绝对值为： 5.0\n"
     ]
    }
   ],
   "source": [
    "# 定义变量x，从用户输入中获取数值\n",
    "x = float(input(\"请输入一个数值：\"))\n",
    "\n",
    "# 定义变量abs_x，用来存放绝对值\n",
    "abs_x = x\n",
    "# 如果x为正数\n",
    "if x > 0:\n",
    "    print(\"x is positive\")\n",
    "    \n",
    "# 如果x为零\n",
    "elif x == 0:\n",
    "    print(\"x is zero\")\n",
    "    \n",
    "# 如果x为负数\n",
    "else:\n",
    "    print(\"x is negative\")\n",
    "\n",
    "    # 计算负数绝对值\n",
    "    abs_x = -x\n",
    "\n",
    "print(\"该数值的绝对值为：\", abs_x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3d92a51-a7d2-4f2f-87f7-7c22dcc7603e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
